package tg.edu.fhh.demo.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.SessionAttributes;

import tg.edu.fhh.demo.security.UserUtils;
import tg.edu.fhh.demo.service.SysUserService;

@Controller
@SessionAttributes(value = {"user"})
public class MainController {
	@Autowired
	private SysUserService userService;
	@Autowired
	private UserUtils userUtils;
	
	
   @RequestMapping(value = {"/","/login"},method=RequestMethod.GET)
	public String login() {
		return "login";
	}
   
   
   @RequestMapping(value = "/main")
   public String main() {
	   if(userUtils.hasRole("ROLE_DIY")) {
		   return "stuMain";
	   }
	   return "main";
   }
   @PreAuthorize(value = "hasRole('ROLE_STUDENT')")
   @RequestMapping(value = "/stuMain")
   public String stuMain() {
	   return "stuMain";
	   
   }
//   @RequestMapping(value = "/login",method=RequestMethod.POST)
//   public String login(String username ,String pwd,ModelMap modelMap) {
//	   SysUser user= userService.login(username, pwd);
//       if(user==null) {
//    	   return "redirect:login";
//       }
//       modelMap.put("user",user);
//       if(user.isRole("ROLE_STUDENT")) {
//    	   return "redirect:stuMain";
//       }else {
//    	   return "redirect:main";
//       }
//   }
}
